/**
 * Created by yyt on 2017/3/21.
 */
var shopNameFlag=true;
var mobileFlag=true;
var passwordFlag=true;
var repassFlag=true;

function checkMobile(){
    var mobile=document.getElementById("mobile");
    var mobileZhengZe=/^1[3587]\d{9}$/;
    mobile.onfocus=function(){
        mobile.nextSibling.innerHTML="";
    }
    mobile.onblur=function() {
        if(mobile.value=="") {
            mobile.nextSibling.style.display = "inline";
            mobile.nextSibling.innerHTML = "请输入电话号码！";
            mobileFlag=false;
        }else if (!mobileZhengZe.test(mobile.value)) {
            mobile.nextSibling.style.display = "inline";
            mobile.nextSibling.innerHTML = "电话号码格式错误！";
            mobileFlag=false;
        }else{
            mobileFlag=true;
        }
    }
}

function checkShopName() {
    var shopName = document.getElementById("shopName");
    shopName.onfocus=function () {
        shopName.nextSibling.innerHTML="";
    }
    shopName.onblur = function () {
        if (shopName.value == "") {
            shopName.nextSibling.style.display = "inline";
            shopName.nextSibling.innerHTML = "请输入店铺名！";
            shopNameFlag=false;
        }else{
            shopNameFlag=true;
        }
    }
}

function checkPassword(){
    var password = document.getElementById("password");
    var repass = document.getElementById("repass");
    password.onfocus=function(){
        password.nextSibling.innerHTML = "";
    }
    password.onblur=function(){
        if(password.value.length< 6){password.nextSibling.innerHTML="密码至少为6位！";passwordFlag=false;}
        else if(password.value==""){password.nextSibling.innerHTML="请输入密码!";passwordFlag=false;}
        else if (repass.value != password.value) {
            repass.nextSibling.style.color = "#c10000";
            repass.nextSibling.style.display = "inline";
            repass.nextSibling.innerHTML = "两次密码不一致！";
            passwordFlag=false;
        }else{
            passwordFlag=true;
        }
    }
}

function checkRepass() {
    var password = document.getElementById("password");
    var repass = document.getElementById("repass");
    repass.onfocus=function(){
        repass.nextSibling.innerHTML = "";
    }
    repass.onblur = function () {
        if (repass.value != password.value) {
            repass.nextSibling.style.color = "#c10000";
            repass.nextSibling.style.display = "inline";
            repass.nextSibling.innerHTML = "两次密码不一致！";
            repassFlag=false;
        } else {
            repass.nextSibling.style.color = "green";
            repass.nextSibling.style.display = "inline";
            repass.nextSibling.innerHTML = "验证通过";
            repassFlag=true;
            passwordFlag=true;
        }
    }
}

function checkAll(){
    if(shopNameFlag && mobileFlag && passwordFlag && repassFlag){return true;}
    else{return false;}
}
window.onload=function(){
    checkShopName();
    checkMobile();
    checkRepass();
    checkPassword();
}